package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ymt.database.MongoDBDriver;
import com.ymttest.database.mongo.bean.HistoryProductBean;

public class HistoryProductModelWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_ProductHis("HistoryProductModel");

	public HistoryProductModelWapper()  {
	}
		
	public Map<String,Object> getBySellerId(int sellerId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"SellerId\":" + sellerId + "}",1);
	    
	    return list.size()>0?list.get(0):null;
	}
	

	
	public Map<String,Object> getByProductId(String productId) throws Exception {
		//ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}", "", 1, "{'_id':-1}");
	    
	    return list.size()>0?list.get(0):null;
	}
	
	public String getByProductIdAsStr(String productId) throws Exception {
		//ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
		return  mdd.selectPartLimit("{\"ProductId\":\"" + productId + "\"}",  1).get(0);
	    
	}
	
	
	public static void main(String[] args) throws Exception {
		System.out.println(new HistoryProductModelWapper().getByProductIdAsStr("f4aa0522-d4fd-4d07-bff9-e5f3c826a8ec").toString());
		Gson gson = new GsonBuilder().setDateFormat("EEE MMM dd HH:mm:ss z yyyy").create();
		HistoryProductBean a = gson.fromJson(new HistoryProductModelWapper().getByProductIdAsStr("f4aa0522-d4fd-4d07-bff9-e5f3c826a8ec").toString(), HistoryProductBean.class);
		
	}
}
